<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子组件向父组件传递数据</title>
</head>
<body>
<div id="app">
    <h2>{{ count }}</h2>

    <cpn v-on:decrease="decrease" v-on:increase="increase"></cpn>
</div>

<template id="cpn">
    <button v-on:click="$emit('decrease', c-=1)">-</button>
    <button v-on:click="$emit('increase', c+=1)">+</button>
</template>

<script type="module">
    import {createApp, defineComponent, ref} from "../../../../js/vue.esm-browser.js";

    let cpn = defineComponent(
        {
            template: "#cpn",
            emits: ["decrease", "increase"],
            setup() {
                let c = 0
                return {c};
            }
        }
    );

    let app = createApp({
        setup() {
            let count = ref(0)

            function increase(event) {
                count.value = event
            }
        

            function decrease(event) {
                count.value -= event
            }

            return {
                count,
                decrease,
                increase,
            }
        },
        components: {
            cpn,
        }
    })
    app.mount("#app")
</script>
</body>
</html>